#include "Mesh.h"
#include "os/Graphics/Graphics.h"
#include "os/Graphics/GraphicsStructs.h"


using namespace leo;

Mesh::Mesh(int _posX, int _posY, int _posZ, std::string _fileName,leo::Texture::Ptr _tex)
{
	textura = _tex;
	posX = _posX;
	posY = _posY;
	posZ = _posZ;

	scale = 100;
	textura->SetColorKey(D3DCOLOR_XRGB(255,255,254));
}

Mesh::~Mesh(void)
{
	
}

void Mesh::OnDraw(leo::Graphics *_graph) const
{
	
	_graph->BindTexture(textura);
	_graph->BindVertexBuffer(const_cast<VertexBuffer<TextureVertex, TEXTURE_VERTEX>*>(vertexBuffer.get()));
	_graph->BindIndexBuffer(const_cast<IndexBuffer*>(indexBuffer.get()));
	_graph->Draw();

}

void Mesh::LoadFromXFile(const std::string& _filename, leo::Graphics& _graph)
{
	XFile* loader = new XFile(_graph);

	loader->LoadMesh(*this, _filename);

	delete loader;
	loader = NULL;
}

void Mesh::SetVertexBuffer(VertexBuffer<TextureVertex, TEXTURE_VERTEX>::Ptr _vertexBuffer)
{
	vertexBuffer = _vertexBuffer;
}
void Mesh::SetIndexBuffer(IndexBuffer::Ptr _indexBuffer)
{
	indexBuffer = _indexBuffer;
}
